package main

import "fmt"

// 简单工厂模式

type Book interface {
	Name() string
}
type chineseBook struct {
	name string
}

func (cb *chineseBook) Name() string {
	return cb.name
}

type mathBook struct {
	name string
}

func (mb *mathBook) Name() string {
	return mb.name
}

type englishBook struct {
	name string
}

func (eb *englishBook) Name() string {
	return eb.name
}

func GetBook(name string) Book {
	if name == "语文书" {
		return &chineseBook{name: "语文书"}
	} else if name == "数学书" {
		return &mathBook{name: "数学书"}
	} else if name == "英语书" {
		return &englishBook{name: "英语书"}
	}
	return nil
}

// 抽象工厂模式，把工厂分类抽象成接口

type Paper interface {
	Name() string
}

type chinesePaper struct {
	name string
}

// 发书人
type Assigner interface {
	GetBook(name string) Book
	GetPaper(string) Paper
}

type assigner struct{}

func (a *assigner) GetBook(name string) Book {
	if name == "语文书" {
		return &chineseBook{name: "语文书"}
	} else if name == "数学书" {
		return &mathBook{name: "数学书"}
	} else if name == "英语书" {
		return &englishBook{name: "英语书"}
	}
	return nil
}

type chineseBookAssigner struct{}

func (cba *chineseBookAssigner) GetBook(name string) Book {
	if name == "语文书" {
		return &chineseBook{
			name: "语文书",
		}
	}
	return nil
}
func main() {
	var a chineseBookAssigner
	fmt.Println(a.GetBook("语文书").Name())

	//简答工厂，抽象工厂
}
